<?php

namespace app\api\controller\Home;

use think\Controller;

class Index extends Controller
{
    //继承父类
    public function __construct()
    {
        parent::__construct();
        $this->ProductModel = model('Product.Product');
        $this->ProductTypeModel = model('Product.ProductType');
    }

    public function index()
    {
        // 分类
        $TypeList = $this->ProductTypeModel->order('weigh', 'desc')->limit(8)->select();
        $NewList = $this->ProductModel->where(['flag' => 1])->limit(4)->select();
        $HotList = $this->ProductModel->where(['flag' => 2])->limit(6)->select();
        $RecList = $this->ProductModel->where(['flag' => 3])->limit(4)->select();

        $data = [
            'TypeList' => $TypeList,
            'NewList' => $NewList,
            'HotList' => $HotList,
            'RecList' => $RecList,
        ];

        if (!empty($data)) {
            $this->success('查询成功', null, $data);
        }
        $this->error('查询失败');
    }

    //小程序轮播图接口数据
    public function  banner()
    {
        $ProductRecommend = model('Product.Product')->where('flag', 1)->limit(5)->select();

        $this->success('查询成功', null, $ProductRecommend);
    }
}
